﻿#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// PandoraFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System;
using System.IO;
using Pandora;
using UnityEngine;

namespace PandoraEditor
{
    public class SettingHelper
    {
        
        public static readonly string SettingPath = Application.dataPath + "/../Pandora/settings";
        
        public static void SaveSingleSetting(object obj)
        {
            PdrFileUtil.SaveTextToFile(SettingPath, obj.GetType().Name, JsonUtility.ToJson(obj));
        }

        public static T LoadSettings<T>() where T : new()
        {
            string strJson = PdrFileUtil.ReadTextFromFile(Path.Combine(SettingPath, typeof(T).Name));
            return String.IsNullOrEmpty(strJson) ? new T() : JsonUtility.FromJson<T>(strJson);
        }
    }
}